/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject.DocSites
{
	public struct QueryOperator : IEquatable<QueryOperator>
	{
		#region Public Properties
		public static readonly QueryOperator None = new QueryOperator();

		public char Symbol
		{
			get
			{
				return symbol;
			}
		}

		public bool IsOptimized
		{
			get
			{
				return optimized;
			}
		}

		public bool IsAssociative
		{
			get
			{
				return associative;
			}
		}
		#endregion

		#region Private / Protected
		private readonly char symbol;
		private readonly bool optimized, associative;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="QueryOperator" /> class.
		/// </summary>
		public QueryOperator(char symbol)
			: this(symbol, false)
		{
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="QueryOperator" /> class.
		/// </summary>
		public QueryOperator(char symbol, bool optimized)
			: this(symbol, optimized, true)
		{
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="QueryOperator" /> class.
		/// </summary>
		public QueryOperator(char symbol, bool optimized, bool associative)
		{
			this.symbol = symbol;
			this.optimized = optimized;
			this.associative = associative;
		}
		#endregion

		#region Method
		public static implicit operator QueryOperator(char symbol)
		{
			return new QueryOperator(symbol);
		}

		public static implicit operator char(QueryOperator op)
		{
			return op.symbol;
		}

		public static bool operator ==(QueryOperator op1, QueryOperator op2)
		{
			return op1.Equals(op2);
		}

		public static bool operator !=(QueryOperator op1, QueryOperator op2)
		{
			return !op1.Equals(op2);
		}

		public override int GetHashCode()
		{
			return symbol.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj is QueryOperator)
				return Equals((QueryOperator) obj);
			else
				return false;
		}

		public override string ToString()
		{
			return symbol.ToString();
		}
		#endregion

		#region IEquatable<QueryOperator> Members
		public bool Equals(QueryOperator other)
		{
			return symbol == other.symbol;
		}
		#endregion
	}
}
